﻿using System.Collections.Generic;
using Jsdl.Domain.Type;
using Newtonsoft.Json;

namespace Jsdl.Domain.Input.JsonService
{
    // TODO default: json when POST; query when GET

    public class JsdlOperation
	{
		public JsdlOperation()
		{
			Parameters = new List<JsdlServiceParameter>();
		}

		[JsonProperty(PropertyName = "transport")]
		public JsdlOperationTransport Transport { get; set; }

		[JsonProperty(PropertyName = "target")]
		public string Target { get; set; }

		[JsonProperty(PropertyName = "description")]
		public string Description { get; set; }

		[JsonProperty(PropertyName = "envelope")]
		public JsdlOperationEnvelope Envelope { get; set; }

		[JsonProperty(PropertyName = "contentType")]
		public string ContentTypeRaw { get; set; }

		[JsonIgnore]
		public string ContentType
		{
			get { return ContentTypeRaw ?? "application/json"; }
		}

		[JsonProperty(PropertyName = "parameters")]
		public List<JsdlServiceParameter> Parameters { get; set; }

		[JsonProperty(PropertyName = "parameter")]
		public JsdlServiceParameter Parameter { get; set; }

		[JsonProperty(PropertyName = "returns")]
		public JsdlType Returns { get; set; }

		[JsonProperty(PropertyName = "maxAge")]
		public int? MaxAgeRaw { get; set; }
	
		[JsonIgnore]
		public int? MaxAge
		{
			get { return MaxAgeRaw.HasValue ? MaxAgeRaw.Value : 0; }
		}
	}
}